home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / STRPLATE.ASM < prev    next >
Assembly Source File  |  1988-08-01  |  4KB  |  89 lines

  1. ;===========================================================================
  2. ;
  3. ;    S T R P L A T E   --  Boilerplate string external function
  4. ;
  5. ;===========================================================================
  6. ;
  7. ;     by Jeff Duntemann      19 February 1988
  8. ;
  9. ;     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann
  10. ;    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5
  11. ;
  12. ; STRPLATE is written to be called from Turbo Pascal V4.0 using the
  13. ; EXTERNAL procedure convention.
  14. ;
  15. ; Declare the procedure itself as external using this declaration:
  16. ;
  17. ; {$L STRPLATE}
  18. ; FUNCTION STRPLATE(Source : String) : String;
  19. ;                                     EXTERNAL;
  20. ;
  21. ; This function doesn't do anything useful; it simply copies the value of
  22. ; Source into the function result.
  23. ;
  24. ; To reassemble/relink STRPLATE:
  25. ;-------------------------------------
  26. ; Assemble this file with MASM.  "C>MASM STRPLATE;"
  27. ;
  28. ; The following value can be set to anything between 1 and 255.  80 and 255
  29. ; are the commonest and most useful values.  It represents the physical
  30. ; length of the string, and MUST match the length of the return string value
  31. ; as declared in the Pascal program for the external function.
  32.  
  33. PHYSLEN   EQU  255
  34.  
  35. ;
  36. ; This structure defines the layout of parameters on the stack.  There is
  37. ; only one parameter, a string value.  Other parameters would replace the
  38. ; PARMPTR field or be added adjacent to it.  Keep in mind that parms
  39. ; declared in the function header AFTER the string parm would be added to
  40. ; ONSTACK in the position ABOVE the PARMPTR field!
  41. ;
  42.  
  43. ONSTACK   STRUC
  44. OLDBP     DW   ?               ;CALLER'S BP VALUE
  45. RETADDR   DW   ?               ;RETURN ADDRESS
  46.  
  47. PARMPTR   DD   ?               ;POINTER TO THE STRING PARAMETER
  48.  
  49. FUNCPTR   DD   ?               ;POINTER TO FUNCTION RESULT WORK AREA
  50. ONSTACK   ENDS
  51.  
  52.  
  53. CODE      SEGMENT BYTE PUBLIC
  54.           ASSUME  CS:CODE
  55.           PUBLIC  STRPLATE
  56.  
  57. STRPLATE  PROC    NEAR         ;MAKE IT A FAR PROC IF IT'S IN A UNIT!
  58.           PUSH    BP           ;SAVE PREVIOUS VALUE OF BP ON STACK
  59.           MOV     BP,SP        ;SP BECOMES NEW VALUE OF BP
  60.  
  61.  
  62. ; The "meat" of your own string function should go between the dashed lines.
  63. ; leave the stuff outside the dashed lines, alone, unless you change the
  64. ; parameter structure or the physical length of the string passed and
  65. ; returned.  An assumption made here is that the physical length of the
  66. ; string parameter is the same as the physical length of the return value.
  67. ; You can easily violate this assumption...but I would advise against it.
  68. ;--------------------------------------------------------------------------
  69.  
  70. ; For an example operation, let's copy the parm into the function result:
  71.  
  72.           PUSH    DS              ;SAVE CALLER'S DS
  73.           LDS     SI,[BP].PARMPTR ;MOVE PARAMETER ADDRESS INTO DS:SI
  74.           LES     DI,[BP].FUNCPTR ;MOVE FUNCTION RESULT ADDRESS INTO ES:DI
  75.           MOV     CX,PHYSLEN+1    ;NUMBER OF BYTES TO MOVE
  76.           CLD                     ;SET DIRECTION FLAG FOR AUTO INCREMENT
  77.           REPZ MOVSB              ;PERFORM THE BLOCK MOVE
  78.  
  79. ;--------------------------------------------------------------------------
  80.  
  81.           POP     DS              ;RESTORE CALLER'S DS VALUE
  82.           MOV     SP,BP           ;RESTORE CALLER'S STACK POINTER
  83.           POP     BP              ;RESTORE CALLER'S BASE POINTER
  84.           RET     FUNCPTR-RETADDR-2   ;CLEAN UP STACK AND RETURN
  85.  
  86. STRPLATE  ENDP
  87. CODE      ENDS
  88.           END
  89.